<?php

/**
 * CourrierElectronique filter form base class.
 *
 * @package    tfe
 * @subpackage filter
 * @author     3emeIG
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseCourrierElectroniqueFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'piece_jointe'                   => new sfWidgetFormFilterInput(),
      'objet'                          => new sfWidgetFormFilterInput(),
      'message'                        => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'created_at'                     => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'updated_at'                     => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate(), 'with_empty' => false)),
      'deleted_at'                     => new sfWidgetFormFilterDate(array('from_date' => new sfWidgetFormDate(), 'to_date' => new sfWidgetFormDate())),
      'contacts_destinataires_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Contact')),
      'groupes_destinataires_list'     => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Groupe')),
      'newsletters_destinataires_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Newsletter')),
      'ateliers_destinataires_list'    => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Atelier')),
      'stages_destinataires_list'      => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Stage')),
      'abonnements_destinataires_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Abonnement')),
    ));

    $this->setValidators(array(
      'piece_jointe'                   => new sfValidatorPass(array('required' => false)),
      'objet'                          => new sfValidatorPass(array('required' => false)),
      'message'                        => new sfValidatorPass(array('required' => false)),
      'created_at'                     => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'updated_at'                     => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'deleted_at'                     => new sfValidatorDateRange(array('required' => false, 'from_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 00:00:00')), 'to_date' => new sfValidatorDateTime(array('required' => false, 'datetime_output' => 'Y-m-d 23:59:59')))),
      'contacts_destinataires_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Contact', 'required' => false)),
      'groupes_destinataires_list'     => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Groupe', 'required' => false)),
      'newsletters_destinataires_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Newsletter', 'required' => false)),
      'ateliers_destinataires_list'    => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Atelier', 'required' => false)),
      'stages_destinataires_list'      => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Stage', 'required' => false)),
      'abonnements_destinataires_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Abonnement', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('courrier_electronique_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addContactsDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.ContactDestinataire ContactDestinataire')
          ->andWhereIn('ContactDestinataire.id_contact', $values);
  }

  public function addGroupesDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.GroupeDestinataire GroupeDestinataire')
          ->andWhereIn('GroupeDestinataire.id_groupe', $values);
  }

  public function addNewslettersDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.NewsletterDestinataire NewsletterDestinataire')
          ->andWhereIn('NewsletterDestinataire.id_newsletter', $values);
  }

  public function addAteliersDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.AtelierDestinataire AtelierDestinataire')
          ->andWhereIn('AtelierDestinataire.id_atelier', $values);
  }

  public function addStagesDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.StageDestinataire StageDestinataire')
          ->andWhereIn('StageDestinataire.id_stage', $values);
  }

  public function addAbonnementsDestinatairesListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.AbonnementDestinataire AbonnementDestinataire')
          ->andWhereIn('AbonnementDestinataire.id_abonnement', $values);
  }

  public function getModelName()
  {
    return 'CourrierElectronique';
  }

  public function getFields()
  {
    return array(
      'id'                             => 'Number',
      'piece_jointe'                   => 'Text',
      'objet'                          => 'Text',
      'message'                        => 'Text',
      'created_at'                     => 'Date',
      'updated_at'                     => 'Date',
      'deleted_at'                     => 'Date',
      'contacts_destinataires_list'    => 'ManyKey',
      'groupes_destinataires_list'     => 'ManyKey',
      'newsletters_destinataires_list' => 'ManyKey',
      'ateliers_destinataires_list'    => 'ManyKey',
      'stages_destinataires_list'      => 'ManyKey',
      'abonnements_destinataires_list' => 'ManyKey',
    );
  }
}
